<template>
  <div id="jobVacancy">
    <div class="jobVacancyContent">
      <div class="worksDetailNavInfo">
        <div><p @click="handleBack()">高端职业</p><span>&gt;</span><p>职位详情</p></div>
      </div>
      <div class="jobVacancyContentBox">
        <div class="jobVacancyContentBoxLeft">
          <h2>招聘职位</h2>
          <h1>{{highendJobData.positionName}}</h1>
          <div class="jobVacancyContentBoxLeftSalary"><span>{{highendJobData.salary}}</span><sub>{{highendJobData.education}}</sub></div>
          <h2>职位描述</h2>
          <p v-html="highendJobData.describing"></p>
          <h2>所属部门</h2>
          <p>{{highendJobData.department}}</p>
          <h2>工作地点</h2>
          <p>{{highendJobData.workAddress}}</p>
        </div>
        <div class="jobVacancyContentBoxRight">
          <div class="jobVacancyContentBoxRightLogo">
            <img :src="$globalImageUrl + highendJobData.avatar" alt="" @click="jumpTo('/recruitJob?id=' + highendJobData.createId)">
            <p style="text-align: center; padding-top: .3rem;">{{highendJobData.userName}} | {{highendJobData.email}}</p>
            <div class="btnBox">
              <button class="btnDef"  @click="handleMessage()">站内信</button>
            </div>
            <!-- 蒙层 -->
            <div class="message" v-show="isMessage">
              <div class="messageBox">
                <div class="messageTitle">站内信</div>
                <div>
                  <textarea v-model="value" cols="30" rows="10"></textarea>
                </div>
                <span class="messageBtn sureBtn" @click="sureMessage()">确认</span>
                <span class="messageBtn" @click="handleMessage()">取消</span>
              </div>
            </div>
          </div>
          <div class="jobVacancyContentBoxRightElseJob">
            <h2>其他职位</h2>
            <div class="jobVacancyContentBoxRightElseJobList" v-for="(item, index) in restsJobData" :key="index" @click="toJobVacancy(item.id)">
              <p><b>{{item.positionName}}</b><i>{{item.salary}}</i></p>
              <p>{{item.years}} | {{item.workAddress}}</p>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import store from '@/store';
export default {
  name: 'jobVacancy',
  data () {
    return {
      userId: store.state.user.userId,
      isMessage: false,
      value: '',
      highendJobId: this.$route.query.highendJobId,
      highendJobData: {},
      restsJobData: {}
    }
  },
  created () {
    this.fetchOneJob()
    this.fetchSameJob()
  },
  methods: {
    handleBack () {
      this.$router.push('/recruitJob')
    },
    // 发私信
    sureMessage () {
      if (this.userId == '') {
        this.$vux.toast.text('请先登录')
        return
      }
      console.log(this.highendJobData)
      this.$api.PostPrivateLetter({
        messageContent: this.value,
        sender: this.userId,
        receiver: this.highendJobData.id
      }).then(res => {
        console.log(res)
        if (res.code === 0) {
          this.$vux.toast.text('发送成功')
          setTimeout(() => {
            this.handleMessage()
            this.value = ''
          }, 500)
        }
      })
    },
    // 显示/隐藏蒙层
    handleMessage () {
      this.isMessage = !this.isMessage
    },
    // 跳转到工作详情
    toJobVacancy (id) {
      this.onOpenExternalLink(`${this.$globalLinkUrl}#/jobVacancy?highendJobId=` + id)
    },
    // 立即沟通
    onCollaborat () {
      this.$vux.confirm.show({
        title: '提示',
        content: '手机：' + this.highendJobData.phone + '<br/>邮箱：' + this.highendJobData.email
      })
    },
    // 获取高端职位详情
    fetchOneJob () {
      this.$api.getOneJob({
        id: this.highendJobId
      }).then(res => {
        console.log(res)
        this.highendJobData = res.data
      })
    },
    // 其他职位
    fetchSameJob () {
      this.$api.getSameJob({
        id: this.highendJobId
      }).then(res => {
        if (res.code === 0) {
          this.restsJobData = res.data
        }
      })
    }
  }
}
</script>

<style lang="less" scoped>
#jobVacancy{
  .message{
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.3);
    padding-top: 200px;
    .messageBox{
      width: 600px;
      height: 400px;
      border-radius: 10px;
      background-color: #fff;
      position: absolute;
      // top: 200px;
      left: 0;
      right: 0;
      margin: 0 auto;
      text-align: center;
      .messageTitle{
        height: 60px;
        border-radius: 10px 10px 0 0;
        color: #fff;
        line-height: 60px;
        background-color: #00918A;
        // left: 50px;
      }
      .messageBtn{
        display: inline-block;
        width: 100px;
        height: 40px;
        border: 1px solid #aaaaaa;
        border-radius: 10px;
        line-height: 40px;
        margin-top: 30px;
      }
      .sureBtn{
        background-color: #00918A;
        color: #fff;
        margin-right: 50px;
      }
      div{
        textarea{
          margin-top: 20px;
          border: 1px solid #b4b4b4;
          border-radius: 10px;
          width: 80%;
          padding: 10px;
        }
      }
    }
  }
  .jobVacancyContent{
    width: 1200px;
    margin: auto;
    padding: .2rem 0;
    .jobVacancyContentBox{
      font-size: 0;
      .jobVacancyContentBoxLeft{
        display: inline-block;
        width: 70%;
        vertical-align: top;
        background-color: #fff;
        padding: .2rem;
        h2{
          font-size: .2rem;
          font-weight: bold;
          color: #333;
          line-height: .28rem;
          padding-bottom: .2rem;
        }
        h1{
          font-size: .28rem;
          font-weight: bold;
          color: #333;
          line-height: .36rem;
        }
        p{
          font-size: .16rem;
          font-weight: 500;
          color: #999;
          line-height: .24rem;
          padding-bottom: .3rem;
        }
        .jobVacancyContentBoxLeftSalary{
          padding: .2rem 0;
          span{
            font-size: .22rem;
            font-weight: 500;
            color: #ff7f00;
            line-height: .3rem;
            vertical-align: middle;
          }
          sub{
            font-size: .16rem;
            font-weight: 500;
            color: #333;
            line-height: .24rem;
            padding-left: .1rem;
            vertical-align: middle;
          }
        }
      }
      .jobVacancyContentBoxRight{
        display: inline-block;
        width: 30%;
        vertical-align: top;
        padding-left: .2rem;
        .jobVacancyContentBoxRightLogo{
          background-color: #fff;
          font-size: .16rem;
          padding-top: .6rem;
          padding-bottom: .4rem;
          img{
            width: 1rem;
            height: 1rem;
            display: block;
            border-radius: .05rem;
            margin: auto;
          }
          .btnBox{
            margin-top: .4rem;
            padding: 0 .8rem;
          }
        }
        .jobVacancyContentBoxRightElseJob{
          margin-top: .2rem;
          background-color: #fff;
          padding: .2rem;
          h2{
            font-size: .2rem;
            font-weight: 500;
            color: #333;
            line-height: .28rem;
            padding-bottom: .2rem;
          }
          .jobVacancyContentBoxRightElseJobList{
            margin-bottom: .1rem;
            p{
              font-size: .14rem;
              font-weight: 500;
              color: #999;
              line-height: .22rem;
              b{
                font-size: .16rem;
                font-weight: 500;
                color: #333;
                line-height: .24rem;
              }
              i{
                font-size: .16rem;
                font-weight: 500;
                color: #999;
                line-height: .24rem;
                font-style: normal;
                float: right;
              }
            }
          }
        }
      }
    }
  }
}
</style>
